// @ts-ignore
/* eslint-disable */
import { request } from '@umijs/max';

/** 获取当前的用户 GET /api/currentUser */
export async function currentUser(options?: { [key: string]: any }) {
  try {
    var json = localStorage.getItem('user')
    if (json) {
      var dbuser = JSON.parse(json)
      const currentUser: API.CurrentUser = {
        name: dbuser.name,
        token: dbuser.token,
        expiresIn: dbuser.expiresIn,
        refreshExpireIn: dbuser.refreshExpireIn,
        refresh_token: dbuser.refresh_token
      }
      return currentUser;
    }
  } catch (error) {

  }
  return undefined
}

/** 退出登录接口 POST /api/login/outLogin */
export async function outLogin(options?: { [key: string]: any }) {
  localStorage.removeItem('user')
  localStorage.removeItem('currentStoreKey')
  localStorage.removeItem('currentStoreName')
  return undefined
}

/** 登录接口 POST /api/login/account */
export async function login(body: API.LoginParams, options?: { [key: string]: any }) {
  return request<API.Result>('/users/signinup', {
    method: 'POST',
    data: body,
    ...(options || {}),
  });
}

/** 此处后端没有提供注释 GET /api/notices */
export async function getNotices(options?: { [key: string]: any }) {
  return request<API.NoticeIconList>('/api/notices', {
    method: 'GET',
    ...(options || {}),
  });
}

/** 获取规则列表 GET /api/rule */
export async function rule(
  params: {
    // query
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
  options?: { [key: string]: any },
) {
  return request<API.RuleList>('/api/rule', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** 新建规则 PUT /api/rule */
export async function updateRule(options?: { [key: string]: any }) {
  return request<API.RuleListItem>('/api/rule', {
    method: 'PUT',
    ...(options || {}),
  });
}

/** 新建规则 POST /api/rule */
export async function addRule(options?: { [key: string]: any }) {
  return request<API.RuleListItem>('/api/rule', {
    method: 'POST',
    ...(options || {}),
  });
}

/** 删除规则 DELETE /api/rule */
export async function removeRule(options?: { [key: string]: any }) {
  return request<Record<string, any>>('/api/rule', {
    method: 'DELETE',
    ...(options || {}),
  });
}


// 库存查询
export async function searchStock(storeNo?:String,params?: {
  page?: number;
  /** 页面的容量 */
  size?: number;
  categoryName?: String;
  stockStatus?: number;
  priceStatus?: number;
  name?: String;
  ascend?: number;
  barcode?: String;
},options?: { [key: string]: any }) {
  return request(`/api/merchant/stockgoods/${storeNo}`, {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

//选择门店
export async function getStores(params: {
  page?: number;
  /** 页面的容量 */
  size?: number;
},options?: { [key: string]: any }) {
  return request('/api/merchant/stores', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

// 商品销量统计
export async function goodsStatistics(params?: {
  page?: number;
  /** 页面的容量 */
  size?: number;
},options?: { [key: string]: any }) {
  return request(`/api/merchant/statistics/goodsStatistics`, {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

// 商品销量统计-下载
export async function goodsStatisticsDld(params?: {
  storeKey?: String;
  startTime?: String;
  endTime?: String;
  humanTag?: String;
},options?: { [key: string]: any }) {
  return request(`/api/merchant/statistics/goodsStatisticsDld`, {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

// 商品分类
export async function getCategory(storeNo?:String,params?: {
  page?: number;
  /** 页面的容量 */
  size?: number;
},options?: { [key: string]: any }) {
  return request(`/api/merchant/category/${storeNo}`, {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}
//商品删除
export async function shopdelete(storeKey?:String,barcode?:String,options?: {
   [key: string]: any }) {
  return request(`/api/merchant/stock/${storeKey}/${barcode}`, {
    method: 'DELETE',
    ...(options || {}),
  });
}
//商品详情
export async function shopmsg( barcode?: String,storeKey?:String,params?: {
  page?: number;
  /** 页面的容量 */
  size?: number;
  storeNo?:string;
  barcode?:string;
  categoryName?: string;
  stockStatus?: number;
  priceStatus?: number;
  name?: String;
  ascend?: number;

},options?: { [key: string]: any }){
  return request(`/api/merchant/goods/${barcode}/${storeKey}`, {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

//修改商品
export async function shopmodify(body: API.Modify,id?:String,storeKey?:String,options?: {
   [key: string]: any }) {
  return request(`/api/merchant/goods/${id}/${storeKey}`, {
    method: 'PUT',
    data: body,
    ...(options || {}),
  });
}

//添加商品
export async function shopadd(body: API.Addshop,storeKey?:String, options?: {
  [key: string]: any }) {
 return request(`/api/merchant/goods/${storeKey}`, {
   method:'POST',
    data:body,
   ...(options || {}),
 });
}
// 入库单列表
export async function getInbound(storeNo?:String,params?: {
  page?: number;
  /** 页面的容量 */
  size?: number;
},options?: { [key: string]: any }) {
  return request(`/api/merchant/inbounds/${storeNo}`, {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

// 入库单详情
export async function getInboundDetail(boundId?:String,params?: {
  page?: number;
  /** 页面的容量 */
  size?: number;
},options?: { [key: string]: any }) {
  return request(`/api/merchant/stockhistory/${boundId}`, {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

// 入库
export async function inbound(storeNo?:String,options?: { [key: string]: any }) {
  return request(`/api/merchant/inbound/${storeNo}`, {
    method: 'POST',
    ...(options || {}),
  });
}

// 出库单列表
export async function getOutbound(storeNo?:String,params?: {
  page?: number;
  /** 页面的容量 */
  size?: number;
},options?: { [key: string]: any }) {
  return request(`/api/merchant/outbounds/${storeNo}`, {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

// 出库
export async function outbound(storeNo?:String,options?: { [key: string]: any }) {
  return request<API.RuleListItem>(`/api/merchant/outbound/${storeNo}`, {
    method: 'POST',
    ...(options || {}),
  });
}

// 出库单详情
export async function getOutboundDetail(boundId?:String,params?: {
  page?: number;
  /** 页面的容量 */
  size?: number;
},options?: { [key: string]: any }) {
  return request(`/api/merchant/stockhistory/${boundId}`, {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

//下载示例文件
export async function downloadFileByUrl(url: String) {
  return request(url, {
    method: 'GET',
  });
}

//商品导出
export async function exportDefaultByUrl(url: String) {
  return request(url, {
    method: 'GET',
  });
}

